package com.example.admin.mybledemo.ota;

/**
 * OTA升级状态枚举
 * 从OtaManager中提取，提供清晰的状态管理
 */

public enum OtaState {
    IDLE("空闲"),
    // 第一阶段状态
    PHASE1_CONNECTING("第一阶段: 正在连接设备"),
    PHASE1_DISCOVERING_SERVICES("第一阶段: 发现服务中"),
    PHASE1_VERSION_CHECK("第一阶段: 检查版本信息"),
    PHASE1_ROM_CHECK("第一阶段: 校验ROM版本"),
    PHASE1_CREDENTIAL_CHECK("第一阶段: 验证设备凭证"),
    PHASE1_UPGRADE_CMD("第一阶段: 发送升级指令"),
    PHASE1_DEVICE_RESTART("第一阶段: 等待设备重启"),
    // 第二阶段状态
    PHASE2_SCANNING_BOOT_DEVICE("第二阶段: 扫描Boot模式设备"),
    PHASE2_CONNECTING("第二阶段: 正在连接Boot模式设备"),
    PHASE2_BOOT_MODE("第二阶段: 验证Boot模式"),
    PHASE2_ERASING_FLASH("第二阶段: 正在擦除闪存"),
    PHASE2_DATA_TRANSFER("第二阶段: 正在传输固件数据"),
    PHASE2_VERIFICATION("第二阶段: 正在校验数据"),
    PHASE2_CHECKSUM("第二阶段: 最终校验和确认"),
    COMPLETED("升级成功"),
    CANCELLED("升级已取消"),
    FAILED("升级失败");
    
    private final String description;
    
    OtaState(String description) {
        this.description = description;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 是否为第一阶段状态
     */
    public boolean isPhase1() {
        return this == PHASE1_CONNECTING || this == PHASE1_VERSION_CHECK || 
               this == PHASE1_ROM_CHECK || this == PHASE1_CREDENTIAL_CHECK ||
               this == PHASE1_UPGRADE_CMD || this == PHASE1_DEVICE_RESTART;
    }
    
    /**
     * 是否为第二阶段状态
     */
    public boolean isPhase2() {
        return this == PHASE2_CONNECTING || this == PHASE2_BOOT_MODE ||
               this == PHASE2_DATA_TRANSFER || this == PHASE2_VERIFICATION ||
               this == PHASE2_CHECKSUM;
    }
    
    /**
     * 是否为进行中状态
     */
    public boolean isInProgress() {
        return this != IDLE && this != COMPLETED && this != FAILED;
    }
    
    /**
     * 是否为终态
     */
    public boolean isTerminal() {
        return this == COMPLETED || this == FAILED;
    }
}